<?php

class PageController extends CController
{
	public function actionEdit()
	{
		if (array_key_exists('alias', $_GET)) {
			$page = Page::model()->find('alias=:alias', array(':alias' => $_GET['alias']));
			
			if ($page) {
				$this->setPageTitle($page->title);
				
				$this->render('edit', array(
					'page'  => $page 
				));
			}
		}
	}
	
	public function actionUpdate()
	{
		$alias = $_GET['alias'];
		
		if (array_key_exists('alias', $_GET)) {
			Page::model()->updateAll(
				array('text' => $_POST['text']),
				'alias=:alias',
				array(':alias' => $_GET['alias'])
			);
			
			FlashMessage::saveInfo(array(
				'title'  => 'Инфо',
				'text'   => 'Страница сохранена'
			));
		}
		
		$this->redirect('/admin/page/' . $_GET['alias'] . '/');
	}
}	
